class Variant {
    String name;
    int value;

    Variant({this.name, this.value});

    factory Variant.fromJson(Map<String, dynamic> json) {
        return Variant(
            name: json['name'],
            value: json['value'],
        );
    }

    factory Variant.fromDatabase(Map<String, dynamic> map, inputRate) {
        var rate = inputRate;
        var price = map["price"];
        print("产品比率：$rate x $price");
        if(map["retail_rate"] != null){
            rate = map["retail_rate"];
            print("规格比率：$rate");
        }
        if(rate != null) {
            if (rate > 0) {
                //比率计算
                price = (map["price"] * rate / 100);
                double fl = price / 10;
                price = fl.floor() * 10;
            } else {
                price = "--";
            }
        }
        return Variant(
            name: map['options_text'],
            value: price,
        );
    }

    Map<String, dynamic> toJson() {
        final Map<String, dynamic> data = new Map<String, dynamic>();
        data['name'] = this.name;
        data['value'] = this.value;
        return data;
    }
}